<template>
	<view class="flex flex-col h-screen">
		<NavBarVue title="待解问题"></NavBarVue>
		<view class="flex-1 overflow-hidden">
			<scroll-view scroll-y="true" class="h-full" @scrolltolower="onReachBottom">
				<view class="px-30" v-if="postList.length">
					<questionsListVue v-for="e,i in postList" :key="i" :val="e"></questionsListVue>
				</view>
				<NoDataVue v-else></NoDataVue>
			</scroll-view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		provide,
	} from 'vue';
	import {
		onShow,
		onLoad,
	} from "@dcloudio/uni-app"
	import userApi from '@/apis/apiList/userApi.js';
	import questionsListVue from '@/components/questionsList.vue';
	const postList = ref([])
	const page = ref(1)
	const loadMore = ref("more")

	onLoad(() => {
		getList()
	})

	const onReachBottom = () => {
		if (loadMore.value == 'more') {
			page.value = page.value + 1
			getList()
		}
	}

	const getList = () => {
		loadMore.value = 'loading'
		userApi.anchorQuestionability({
			"anchor.id": uni.getStorageSync('anchor').id,
			sts: 0,
			page: page.value,
			limit: 10
		}).then(res => {
			if (page.value == 1) {
				postList.value = res.data
			} else {
				postList.value = [...postList.value, ...res.data]
			}
			if (res.data.length == 0) {
				loadMore.value = 'noMore'
			} else {
				loadMore.value = 'more'
			}
		})
	}
</script>

<style lang="scss" scoped>
</style>